<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>学校信息</h1>
        <h2>学习名称：{{name}}</h2>
        <h2>学习地址：{{address}}</h2>
        <hr>
        <h1>学生信息</h1>
        <button @click="addSex">添加一个性别数学系，默认值是男</button>
        <h2>学生姓名：{{student.name}}</h2>
        <h2>爱好</h2>
        <ul>
            <li v-for="(h, index) in student.hobby" :key="index">
                {{h}}
            </li>
        </ul>
        <hr>
        <h2 v-if='student.sex'>学生性别：{{student.sex}}</h2>
        <h2>学生年龄：真实{{student.age.rAge}}, 对外{{student.age.sAge}}</h2>
        <ul>
            <li v-for="(f, index) in student.friends" :key="index">
                {{f.name}}-{{f.age}}
            </li>
        </ul>
        <hr>
      </div>
  
      <script>
        const vm = new Vue({
          el: "#root",
          data: {
              name: '尚硅谷',
              address: '北京',
              student: {
                  name: 'tom',
                  age: {
                      rAge: 40,
                      sAge: 29
                  },
                  hobby:['抽烟', '喝酒', '烫头'],
                  friends: [
                      {name: 'jerry', age: 35},
                      {name: 'cookie', age: 25}
                  ]
              }
          },
          methods: {
              addSex() {
                  this.$set(this.student, 'sex', '男')
              }
          },
        })
      </script>
</body>
</html>